<?php
/* @var $this ColorController */
/* @var $model Color */
$this->pageTitle = Yii::app()->name . ' - '.Yii::t('default', 'Article');
$this->breadcrumbs=array(
	Yii::t('default', 'Articles'),
);

$this->menu=array(
array('label'=>Yii::t('default', 'Create'), 'url'=>array('create')),
);
?>

<h3>
<?php echo Yii::t('default', 'List').' '.Yii::t('default', 'Articles') ?>
</h3>

<?php 
$pageSize = Yii::app()->user->getState('pageSize', 10);

$this->widget('zii.widgets.grid.CGridView', array(
  'id'           => 'article-grid',
  'dataProvider' => $model->search(),
  'rowCssClassExpression' => '"items[]_{$data->id}"',
  'afterAjaxUpdate' => 'installSortable',
  'filter'       => !empty($articles) ? $model : null,
  'pager'        => array
	(
    'firstPageLabel'       => '&lt;&lt;',
    'prevPageLabel'        => '&lt;',
    'nextPageLabel'        => '&gt;',
    'lastPageLabel'        => '&gt;&gt;',
    'footer'               =>'',
    'header'               =>'',
    'selectedPageCssClass' => 'selected',
    'firstPageCssClass'    => '',
    'lastPageCssClass'     => '',
    'nextPageCssClass'     => '',
    'previousPageCssClass' => '',
    'internalPageCssClass' => '',
    'htmlOptions'          => array(
	    'class' => ''
	  )
	),
  'pagerCssClass' => 'pagination',
  'columns'       =>array(
		array(
      'value' => "getNoOrder($this->stt_gridview)",
      'type' => 'raw'
    ),
    array(
      'name' => 'image',
      'value' => '$data->getArticleImage($data->id, 90, 85)',
      'type' => 'raw',
      'filter' => ''
    ),
    'title',
    array(
      'name' => 'description',
      'type' => 'raw'
    ),
    array(
      'name'  =>'enabled',
      'value' =>'($data->enabled==1)?Yii::t("default", "Yes"):Yii::t("default", "No")',
      'filter' => ''
		),
		array(
			'class'=>'CButtonColumn',
		),
	),
	'htmlOptions' => array(
	  'class' => ''
  )
)); ?>
<div class="row_per_page">
<?php 
  $all = $model->count();
  echo Yii::t('default', 'Row per page: ').CHtml::dropDownList('pageSize',$pageSize,array(10=>10,20=>20,50=>50,$all=>Yii::t('default', 'All')),array(
        'onchange'=>"$.fn.yiiGridView.update('article-grid',{ data:{pageSize: $(this).val() }})",
    ))
?>
</div>
<script type="text/javascript">
function installSortable() {
  var fixHelper = function(e, ui) {
    ui.children().each(function() {
        $(this).width($(this).width());
    });
    return ui;
};
  $('#article-grid table.items tbody').sortable({
    forcePlaceholderSize: true,
    forceHelperSize: true,
    items: 'tr',
    update : function () {
        serial = $('#article-grid table.items tbody').sortable('serialize', {key: 'items[]', attribute: 'class'});
        $.ajax({
            'url': baseUrl + '/admin/article/sort',
            'type': 'post',
            'data': serial,
            'success': function(data){
              $.fn.yiiGridView.update('article-grid');
            },
            'error': function(request, status, error){
                alert('We are unable to set the sort order at this time.  Please try again in a few minutes.');
            }
        });
    },
    helper: fixHelper
  }).disableSelection();
}
$(function() {
  installSortable();
});
</script>